'use strict';
/* jshint unused: false */

/**
 * @ngdoc overview
 * @name openshiftConsole
 * @description
 * # openshiftConsole
 *
 * Main module of the application.
 */
angular
	.module('openshiftConsole', [
		'ngAnimate',
		'ngCookies',
		'ngResource',
		'ngRoute',
		'ngSanitize',
		'ngTouch',
		'openshiftUI',
		'kubernetesUI',
		'ui.bootstrap',
		'patternfly.charts',
		'openshiftConsoleTemplates',
		'ui.ace',
		'pascalprecht.translate'
	])
	.constant("mainNavTabs", []) // even though its not really a "constant", it has to be created as a constant and not a value
	// or it can't be referenced during module config
	// configure our tabs and routing
	.config(['mainNavTabs', '$routeProvider', 'HawtioNavBuilderProvider', '$translateProvider', function(tabs, $routeProvider, builder, $translateProvider) {
		//这个是翻译用的
		var cn = {
            'Loading':'加载中',
            'Projects':'所有项目',
            'NewProject':'新的工程',
            'About':'关于',
            'Help':'帮助',
            'Logout':'退出',
            'Name':'名称',
            'LastBuild':'上次构建时间',
            'Status':'状态',
            'Created':'创建时间',
            'Type':'类型',
            'Source':'源',
            'Addtoproject':'添加到工程',
            'Documentation':'文档',
            'Details':'详情',
            'my-project':'我的工程',
            'uniquename':'为项目取个独一无二的名称',
            'choosedifferent':'这个项目名称已经被使用. 请输入另一个项目名称.',
            'namesmayonly':'项目名称只能包含小写字母、数字和破折号,并且破折号不能出现在开头和末尾',
            'DisplayName':'显示名称',
            'Description':'描述',
            'Ashortdescription':'简单的描述一下您的项目',
            'Create':'提交',
           	'Cancel':'取消',
           	'Delete':'删除',
           	'Getstarted':'开始您的项目',
           	'buildanapplicatio':'用源代码或者是示例库来构建应用映象,或者添加类似于数据库和消息队列这样的组件.',
           	'LastDeployment':'最后部署',
           	'Trigger':'触发',
           	'Nodeployments':'没有部署',
           	'Unknown':'未知',
           	'Time':'时间',
           	'Kind':'类型',
           	'Reason':'原因',
           	'Message':'消息',
           	'ImageStreams':'镜像流',
           	'DockerRepo':'Docker Repo',
           	'Tags':'标签',
           	'Updated':'更新',
           	'none':'无',
            'ContainersReady':'容器准备',
           	'ContainerRestarts':'容器重启',
           	'Age':'Age',
           	'Severity':'Severity',
			      'ClusterIP':'组件IP',
           	'ExternalIP':'外部IP',
           	'Ports':'端口',
           	'Selector':'选择器',
           	'Capacity':'容量',
           	'PersistentVolumeClaims':'持续的量要求',
           	'AccessModes':'访问方式',
           	'ProjectSettings':'项目设置',
           	'Edit':'编辑',
           	'Quota':'配额',
           	'Nodisplayname':'没有设置显示名称',
           	'Nodescription':'没有设置描述',
           	'Save':'保存',
           	'Generalinformation':'主要信息',
           	'Close':'关闭',
           	'Started':'启动',
           	'notstarted':'未启动',
           	'Duration':'持续时间',
           	'Overview':'概观',
           	'Browse':'浏览',
           	'Settings':'设置',
           	'Builds':'构建',
           	'Deployments':'部署',
           	'Events':'事件',
           	'Image Streams':'镜像集',
           	'Pods':'集群',
           	'Routes':'路由',
           	'Services':'服务',
           	'Storage':'存储',
           	'CreateRoute':'创建路由',
           	'Hostname':'主机名',
           	'RoutesTo':'路由目标',
           	'TargetPort':'目标端口',
           	'TLSTermination':'TLS终止',
           	'Aclusteradmin':'管理员可在客户端运行以下命令将您添加为工程的管理员',
           	'projectname':'工程名称',
           	'Noiort':'没有镜像或者魔板',
           	'openshift':'openshift',
           	'namespace':'名称空间',
           	'Animagetoadd':'需要镜像或者模板来添加内容',
           	'Noimagesforsh':'这个工程没有已经加载或者共享的模板',
           	'Toloadrun':'要从文件中加载图像流或模板，运行该命令',
           	'Backtooverview':'返回概观',
           	'LimitRange':'限制范围',
           	'limitRangeHelp':'定义运行时资源如存储器和CPU的最小和最大限制.',
           	'emptyMessageLimitRanges':'项目没有设置任何限制范围.',
           	'quotaHelp':'限制项目内的资源使用',
           	'emptyMessageQuotas':'项目没有设置任何资源配额',
           	'stroageemptyMessage':'暂无数据',
           	'Selectors':'选择器',
           	'Sessionaffinity':'会话关系',
           	'Actions':'行为',
           	'NodePort':'节点端口',
           	'ServicePort':'服务端口',
           	'Service':'服务',
           	'Therearedeployments':' 这个服务没有集群或部署.',
           	'Image':'镜像',
           	'Container':'容器',
           	'Build':'建立',
           	'Mount':'安装',
           	'Memory':'记忆',
           	'Deployment':'部署',
           	'Cancelled':'取消',
           	'Failed':'失败',
           	'Inprogress':'进行中',
           	'Scaleup':'放大',
           	'Scaledown':'缩小',
           	'ReplicationController':'复制控制器',
           	'fromconfigchange':'从配置改变',
           	'Builderimage':'构建镜像',
           	'Sourcetype':'源类型',
           	'Sourcerepo':'源回购',
           	'Sourceref':'源参考',
           	'Sourcecontextdir':'源上下文目录',
           	'Outputimage':'输出镜像',
           	'Push secret':'推送密钥',
           	'StartBuild':'开始构建',
           	'Nobuilds':'没有构建',
           	'buildsemptyMessage':'暂无数据',
           	'Summary':'主要',
           	'Startanewbuild1':'',
           	'sourcerepository':'开始一个新的构建通过源代码库创建一个镜像',
            'Selectanobject':'点击一个对象查看详情',
            'A': '一个',
            'pod': '集群',
           	'service':'服务',
           	'deployment':'部署',
           	'containsoneor':'包含一个或多个Docker容器一起运行在一个节点上，包含您的应用程序代码',
           	'groupspodsand':'组集群提供了一个通用的DNS名称和一个可选的，负载平衡的IP地址来访问它们',
           	'isanupdate':'是一个更新到您的应用程序，所引发的改变的图像或配置',
            'deleteproject':'你确定要删除',
            'this':'这',
            'will':'将',
            'deleteresource':'删除与该项目',
            'associated':'相关的所有资源',
            'and':'和',
            'cannotundone':'无法恢复',
            'makesure':'确保这真的是你想做的事！',
            'about':'关于',
            'servicedevelop':'是Red Hat的平台即服务(PaaS) ,它允许开发人员快速开发,主机 ，',
            'environment':'和规模应用程序在云环境中。',
            'Version':'版本',
            'commandtool':'命令行工具',
            'commandline':'OpenShift 命令行界面(CLI),您可以创建应用程序和终端管理OpenShift项目。',
            'download':'你可以使用下面的链接下载',
            'clienttool':'的客户端工具。',
            'downloadinstall':'关于下载和安装的更多信息 ，',
            'refer':'请参考',
            'start':'并开始使用',
            'documentation':'文档。',
            'Download ':'下载',
            'created':'创建',
            'Configuration':'配置',
            'Environment':'环境',
            'Thebuildstrategy':'构建策略没有定义的环境变量',
            'Buildstrategy':'构建策略',
            'Outputto':'输出',
            'Triggers':'触发器',
            'GitHubwebhookURL':'GitHub webhook URL',
            'Newimagefor':'新镜像',
            'Configchangefor':'设置改变',
            'Manual':'手册',
            'Learnmore':'查看更多',
            'GenericwebhookURL':'Generic webhook URL',
            'ShowURL':'显示链接',
            'Showannotations':'显示注释',
            'Hideannotations':'隐藏注释',
            'description':'描述',
            'Defines how to build the application':'定义如何构建应用程序',
            'EditYAML':'编辑YAML',
            'ViewLog':'查看日志',
            'Latestbuild':'最新构建',
            'failed':'失败',
            'complete':'完成',
            'encounteredanerror':'遇到一个错误',
            'wascancelled':'已取消',
            'An error occurred while starting the build.':'开始构建时遇到一个错误',
            'Detail':'细节',
            'events':'事件',
            'Configura':'配置',
            'Strategy':'策略',
            'UpdatePeriod':'更新时间：',
            'Interval':'间隔:',
            'Timeout':'超时:',
            'Newimage':'新图片',
            'Changeof':'变化',
            'Config':'配置',
            'Template':'模板',
            'Replicas':'副本：',
            'Volumes':'容量',
            'Attachstorage':'附加存储',
            'Logs':'日志',
            'Deploymentconfig':'部署配置:',
            'Phase':'阶段：',
            'Node':'节点：',
            'Restartpolicy':'重启政策：',
            'State':'状态',
            'Ready':'准备就绪',
            'RestartCount':'重新启动数',




    };
        var en = {
        	'Loading':'Loading',
            'Projects':'Projects',
            'NewProject':'New Project',
            'About':'About',
            'Help':'Help',
            'Logout':'Log out',
            'Builds':'Builds',
            'Name':'Name',
            'LastBuild':'Last Build',
            'Status':'Status',
            'Created':'Created',
            'Type':'Type',
            'Source':'Source',
            'Addtoproject':'Add to project',
            'Documentation':'Documentation',
            'Overview':'Overview',
            'Details':'Details',
            'my-project':'my-project',
            'uniquename':'A unique name for the project',
            'choosedifferent':'This name is already in use. Please choose a different name.',
            'namesmayonly':'Project names may only contain lower-case letters, numbers, and dashes.They may not start or end with a dash.',
           	'Description':'Description',
           	'Ashortdescription':'A short description.',
           	'Create':'Create',
           	'Cancel':'Cancel',
           	'Delete':'Delete',
           	'Getstarted':'Get started with your project.',
           	'buildanapplicatio':'Use your source or an example repository to build an applicatio image, or add components like databases and message queues.',
           	'Deployments':'Deployments',
           	'LastDeployment':'LastDeployment',
           	'Trigger':'Trigger',
           	'Nodeployments':'No deployments',
           	'Unknown':'Unknown',
           	'Events':'Events',
           	'Time':'Time',
           	'Kind':'Kind',
           	'Reason':'Reason',
           	'Message':'Message',
           	'ImageStreams':'Image Streams',
           	'DockerRepo':'Docker Repo',
           	'Tags':'Tags',
           	'Updated':'Updated',
           	'none':'none',
           	'Pods':'Pods',
           	'ContainersReady':'Containers Ready',
           	'ContainerRestarts':'Container Restarts',
           	'Age':'Age',
           	'Severity':'Severity',
           	'Services':'Services',
           	'ClusterIP':'Cluster IP',
           	'ExternalIP':'External IP',
           	'Ports':'Ports',
           	'Selector':'Selector',
           	'Storage':'Storage',
           	'PersistentVolumeClaims':'Persistent Volume Claims',
           	'Capacity':'Capacity',
           	'AccessModes':'Access Modes',
           	'ProjectSettings':'Project Settings',
           	'Edit':'Edit',
           	'Quota':'Quota',
           	'Nodisplayname':'No displayname',
           	'Nodescription':'No description',
           	'Save':'Save',
           	'Generalinformation':'General information',
           	'Close':'Close',
           	'Started':'Started',
           	'notstarted':'not started',
           	'Duration':'Duration',
           	'Browse':'Browse',
           	'Settings':'Settings',
           	'Image Streams':'Image Streams',
           	'Routes':'Routes',
           	'CreateRoute':'Create Route',
           	'Hostname':'Hostname',
           	'RoutesTo':'Routes To',
           	'TargetPort':'Target Port',
           	'TLSTermination':'TLS Termination',
           	'Aclusteradmin':'A cluster admin can create a project for you by running the command',
           	'projectname':'projectname',
           	'Noiort':'No images or templates',
           	'openshift':'openshift',
           	'namespace':'namespace',
           	'Animagetoadd':'An image or template is required to add content',
           	'Noimagesforsh':'No images or templates are loaded for this project or the shared',
           	'Toloadrun':'To load an image stream or template from a file, run the command',
           	'Backtooverview':'Back to overview',
           	'LimitRange':'Limit Range',
           	'limitRangeHelp':'Defines minimum and maximum constraints for runtime resources such as memory and CPU.',
           	'emptyMessageLimitRanges':'There are no limit ranges set on this project.',
           	'quotaHelp':'Limits resource usage within the project.',
           	'emptyMessageQuotas':'There are no resource quotas set on this project.',
           	'stroageemptyMessage':'No persistent volume claims to show',
           	'Selectors':'Selectors',
           	'Sessionaffinity':'Session affinity',
           	'Actions':'Actions',
          	'NodePort':'Node Port',
           	'ServicePort':'Service Port',
           	'Service':'Service',
           	'Therearedeployments':' There are no pods or deployments for this service.',
          	'Image':'Image',
           	'Container':'Container',
           	'Build':'Build',
           	'Mount':'Mount',
           	'Memory':'Memory',
           	'Deployment':'Deployment',
           	'Cancelled':'Cancelled',
           	'Failed':'Failed',
           	'Inprogress':'In progress',
           	'Scaleup':'Scale up',
           	'Scaledown':'Scale down',
           	'ReplicationController':'Replication Controller',
           	'fromconfigchange':'from config change',
           	'Builderimage':'Builder image',
           	'Sourcetype':'Source type',
           	'Sourcerepo':'Source repo',
           	'Sourceref':'Source ref',
           	'Sourcecontextdir':'Source context dir',
           	'Outputimage':'Output image',
           	'Push secret':'Push secret',
           	'StartBuild':'Start Build',
           	'Nobuilds':'No builds',
           	'buildsemptyMessage':'No builds to show',
           	'Summary':'Summary',
           	'Startanewbuild1':'Start a new build to create an image from',
           	'sourcerepository':'source repository',
            'Selectanobject':'Select an object to see more details',
            'A': 'A ',
            'pod': 'pod ',
           	'service':'service ',
           	'deployment':'deployment ',
           	'containsoneor':'contains one or more Docker containers that run together on a node, containing your application code ',
           	'groupspodsand':'groups pods and provides a common DNS name and an optional, load-balanced IP address to access them ',
           	'isanupdate':'isanupdate to your application, triggered by a changed image or configuration ',
            'deleteproject':'Are you sure you want to delete the',
            'this':'This ',
            'will':'will',
            'deleteresource':'delete all resources',
            'associated':'associated with the project',
            'and':'and',
            'cannotundone':'cannot be undone',
            'makesure':'Make sure this is something you really want to do!',
            'about':'About',
            'servicedevelop':'is Red Hat’s Platform-as-a-Service (PaaS) that allows developers to quickly develop, host,',
            'environment':'and scale applications in a cloud environment.',
            'Version':'Version',
            'commandtool':'Command Line Tools',
            'commandline':'With the OpenShift command line interface (CLI), you can create applications and manage OpenShift projects from a terminal.',
            'download':'You can download the',
            'clienttool':'client tool using the links below.',
            'downloadinstall':'For more information about downloading and installing it,',
            'refer':'please refer to the',
            'start':'Get Started with the',
            'documentation':'documentation',
            'created':'created',
            'Configuration':'Configuration',
            'Environment':'Environment',
            'Thebuildstrategy':'The build strategy had no environment variables defined',
            'Buildstrategy':'Build strategy',
            'Outputto':'Output to',
            'Triggers':'Triggers',
            'GitHubwebhookURL':'GitHub webhook URL',
            'Newimagefor':'New image for',
            'Configchangefor':'Config change for',
            'Manual':'Manual',
            'Learnmore':'Learn more',
            'GenericwebhookURL':'Generic webhook URL',
            'ShowURL':'Show URL',
            'Showannotations':'Show annotations',
            'Hideannotations':'Hide annotations',
            'description':'description',
            'Defines how to build the application':'Defines how to build the application',
            'EditYAML':'Edit YAML',
            'ViewLog':'View Log',
            'Latestbuild':'Latest build',
            'failed':'failed',
            'complete':'complete',
            'encounteredanerror':'encountered an error',
            'wascancelled':'was cancelled',
            'An error occurred while starting the build':'An error occurred while starting the build',
            'Detail':'Details',
            'events':'Events',
            'Configura':'Configuration',
            'Strategy':'Strategy',
            'UpdatePeriod':'Update Period:',
            'Interval':'Interval:',
            'Timeout':'Timeout',
            'Newimage':'New image for:',
            'Changeof':'Change of:',
            'Config':'Config',
            'Template':'Template',
            'Replicas':'Replicas:',
            'Volumes':'Volumes',
            'Attachstorage':'Attach storage',
            'Logs':'Logs',
            'Deploymentconfig':'Deployment config',
            'Phase':'Phase',
            'Node':'Node:',
            'State':'State',
            'Ready':'Ready',
            'RestartCount':'Restart Count:',




        };

		var lang = window.localStorage.lang || 'cn';
		window.localStorage.lang=lang;
		$translateProvider.translations('cn',cn);
     	$translateProvider.translations('en',en);
		$translateProvider.preferredLanguage(lang);
//		var a = $translateProvider.useStaticFilesLoader({
//			prefix: './i18n/',
//			suffix: '.json'
//		});

//		//这个是翻译用的
		var template = function() {
			return "<sidebar-nav-item></sidebar-nav-item>";
		};

		var projectHref = function(path) {
			return function() {
				var injector = HawtioCore.injector;
				if (injector) {
					var routeParams = injector.get("$routeParams");
					if (routeParams.project) {
						return "project/" + encodeURIComponent(routeParams.project) + "/" + path;
					}
				}
				return "project/:project/" + path;
			};
		};

		var templatePath = "views";
		var pluginName = "openshiftConsole";
		var tab = builder.create()
			.id(builder.join(pluginName, "overview"))
			.title(function() {
				return "Overview";
			})
			.template(template)
			.href(projectHref("overview"))
			.page(function() {
				return builder.join(templatePath, 'project.html');
			})
			.build();
		tab.icon = "dashboard";
		tabs.push(tab);

		tab = builder.create()
			.id(builder.join(pluginName, "browse"))
			.title(function() {
				return "Browse";
			})
			.template(template)
			.href(projectHref("browse"))
			.subPath("Builds", "builds", builder.join(templatePath, 'builds.html'))
			.subPath("Deployments", "deployments", builder.join(templatePath, 'deployments.html'))
			.subPath("Events", "events", builder.join(templatePath, 'events.html'))
			.subPath("Image Streams", "images", builder.join(templatePath, 'images.html'))
			.subPath("Pods", "pods", builder.join(templatePath, 'pods.html'))
			.subPath("Routes", "routes", builder.join(templatePath, 'browse/routes.html'))
			.subPath("Services", "services", builder.join(templatePath, 'services.html'))
			.subPath("Storage", "storage", builder.join(templatePath, 'storage.html'))
			.build();
		tab.icon = "sitemap";
		tabs.push(tab);

		tab = builder.create()
			.id(builder.join(pluginName, "settings"))
			.title(function() {
				return "Settings";
			})
			.template(template)
			.href(projectHref("settings"))
			.page(function() {
				return builder.join(templatePath, 'settings.html');
			})
			.build();
		tab.icon = "sliders";
		tabs.push(tab);

	}])
	.config(function($routeProvider) {
		$routeProvider
			.when('/', {
				templateUrl: 'views/projects.html',
				controller: 'ProjectsController'
			})
			.when('/create-project', {
				templateUrl: 'views/create-project.html',
				controller: 'CreateProjectController'
			})
			.when('/project/:project', {
				redirectTo: function(params) {
					return '/project/' + encodeURIComponent(params.project) + "/overview";
				}
			})
			.when('/project/:project/overview', {
				templateUrl: 'views/project.html',
				controller: 'OverviewController'
			})
			.when('/project/:project/settings', {
				templateUrl: 'views/settings.html',
				controller: 'SettingsController'
			})
			.when('/project/:project/browse', {
				redirectTo: function(params) {
					return '/project/' + encodeURIComponent(params.project) + "/browse/pods"; // TODO decide what subtab to default to here
				}
			})
			.when('/project/:project/browse/builds', {
				templateUrl: 'views/builds.html',
				controller: 'BuildsController'
			})
			.when('/project/:project/browse/builds/:buildconfig', {
				templateUrl: 'views/browse/build-config.html',
				controller: 'BuildConfigController'
			})
			.when('/project/:project/edit/builds/:buildconfig', {
				templateUrl: 'views/edit/build-config.html',
				controller: 'EditBuildConfigController'
			})
			.when('/project/:project/browse/builds/:buildconfig/:build', {
				templateUrl: function(params) {
					if (params.view === 'chromeless') {
						return 'views/logs/chromeless-build-log.html';
					}

					return 'views/browse/build.html';
				},
				controller: 'BuildController'
			})
			// For when a build is missing a buildconfig label
			// Needs to still be prefixed with browse/builds so the secondary nav active state is correct
			.when('/project/:project/browse/builds-noconfig/:build', {
				templateUrl: 'views/browse/build.html',
				controller: 'BuildController'
			})
			.when('/project/:project/browse/deployments', {
				templateUrl: 'views/deployments.html',
				controller: 'DeploymentsController'
			})
			.when('/project/:project/browse/deployments/:deploymentconfig', {
				templateUrl: 'views/browse/deployment-config.html',
				controller: 'DeploymentConfigController'
			})
			.when('/project/:project/browse/deployments/:deploymentconfig/:deployment', {
				templateUrl: function(params) {
					if (params.view === 'chromeless') {
						return 'views/logs/chromeless-deployment-log.html';
					}

					return 'views/browse/deployment.html';
				},
				controller: 'DeploymentController'
			})
			// Needs to still be prefixed with browse/deployments so the secondary nav active state is correct
			.when('/project/:project/browse/deployments-replicationcontrollers/:replicationcontroller', {
				templateUrl: 'views/browse/replication-controller.html',
				controller: 'DeploymentController'
			})
			.when('/project/:project/browse/events', {
				templateUrl: 'views/events.html',
				controller: 'EventsController'
			})
			.when('/project/:project/browse/images', {
				templateUrl: 'views/images.html',
				controller: 'ImagesController'
			})
			.when('/project/:project/browse/images/:image', {
				templateUrl: 'views/browse/image.html',
				controller: 'ImageController'
			})
			.when('/project/:project/browse/pods', {
				templateUrl: 'views/pods.html',
				controller: 'PodsController'
			})
			.when('/project/:project/browse/pods/:pod', {
				templateUrl: function(params) {
					if (params.view === 'chromeless') {
						return 'views/logs/chromeless-pod-log.html';
					}

					return 'views/browse/pod.html';
				},
				controller: 'PodController'
			})
			.when('/project/:project/browse/services', {
				templateUrl: 'views/services.html',
				controller: 'ServicesController'
			})
			.when('/project/:project/browse/services/:service', {
				templateUrl: 'views/browse/service.html',
				controller: 'ServiceController'
			})
			.when('/project/:project/browse/storage', {
				templateUrl: 'views/storage.html',
				controller: 'StorageController'
			})
			.when('/project/:project/browse/persistentvolumeclaims/:pvc', {
				templateUrl: 'views/browse/persistent-volume-claim.html',
				controller: 'PersistentVolumeClaimController'
			})
			.when('/project/:project/browse/routes', {
				templateUrl: 'views/browse/routes.html',
				controller: 'RoutesController'
			})
			.when('/project/:project/browse/routes/:route', {
				templateUrl: 'views/browse/route.html',
				controller: 'RouteController'
			})
			.when('/project/:project/create-route', {
				templateUrl: 'views/create-route.html',
				controller: 'CreateRouteController'
			})
			.when('/project/:project/attach-pvc', {
				templateUrl: 'views/attach-pvc.html',
				controller: 'AttachPVCController'
			})
			.when('/project/:project/create', {
				templateUrl: 'views/create.html',
				controller: 'CreateController'
			})
			.when('/project/:project/create/fromtemplate', {
				templateUrl: 'views/newfromtemplate.html',
				controller: 'NewFromTemplateController'
			})
			.when('/project/:project/create/fromimage', {
				templateUrl: 'views/create/fromimage.html',
				controller: 'CreateFromImageController'
			})
			.when('/project/:project/create/next', {
				templateUrl: 'views/create/next-steps.html',
				controller: 'NextStepsController'
			})
			.when('/project/:project/set-limits', {
				templateUrl: 'views/set-limits.html',
				controller: 'SetLimitsController'
			})
			.when('/about', {
				templateUrl: 'views/about.html',
				controller: 'AboutController'
			})
			.when('/oauth', {
				templateUrl: 'views/util/oauth.html',
				controller: 'OAuthController'
			})
			.when('/error', {
				templateUrl: 'views/util/error.html',
				controller: 'ErrorController'
			})
			.when('/logout', {
				templateUrl: 'views/util/logout.html',
				controller: 'LogoutController'
			})
			// legacy redirects
			.when('/createProject', {
				redirectTo: '/create-project'
			})
			.when('/project/:project/createRoute', {
				redirectTo: '/project/:project/create-route'
			})
			.when('/project/:project/attachPVC', {
				redirectTo: '/project/:project/attach-pvc'
			})
			.otherwise({
				redirectTo: '/'
			});
	})
	.constant("API_CFG", angular.extend({}, (window.OPENSHIFT_CONFIG || {}).api))
	.constant("APIS_CFG", angular.extend({}, (window.OPENSHIFT_CONFIG || {}).apis))
	.constant("AUTH_CFG", angular.extend({}, (window.OPENSHIFT_CONFIG || {}).auth))
	.constant("LOGGING_URL", (window.OPENSHIFT_CONFIG || {}).loggingURL)
	.constant("METRICS_URL", (window.OPENSHIFT_CONFIG || {}).metricsURL)
	.constant("LIMIT_REQUEST_OVERRIDES", _.get(window.OPENSHIFT_CONFIG, "limitRequestOverrides"))
	// Sometimes we need to know the css breakpoints, make sure to update this
	// if they ever change!
	.constant("BREAKPOINTS", {
		screenXsMin: 480, // screen-xs
		screenSmMin: 768, // screen-sm
		screenMdMin: 992, // screen-md
		screenLgMin: 1200, // screen-lg
		screenXlgMin: 1600 // screen-xlg
	})
	.constant('SOURCE_URL_PATTERN', /^((ftp|http|https|git):\/\/(\w+:{0,1}[^\s@]*@)|git@)?([^\s@]+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/)
	.config(function($httpProvider, AuthServiceProvider, RedirectLoginServiceProvider, AUTH_CFG, API_CFG, kubernetesContainerSocketProvider) {
		$httpProvider.interceptors.push('AuthInterceptor');

		AuthServiceProvider.LoginService('RedirectLoginService');
		AuthServiceProvider.LogoutService('DeleteTokenLogoutService');
		// TODO: fall back to cookie store when localStorage is unavailable (see known issues at http://caniuse.com/#feat=namevalue-storage)
		AuthServiceProvider.UserStore('LocalStorageUserStore');

		RedirectLoginServiceProvider.OAuthClientID(AUTH_CFG.oauth_client_id);
		RedirectLoginServiceProvider.OAuthAuthorizeURI(AUTH_CFG.oauth_authorize_uri);
		RedirectLoginServiceProvider.OAuthRedirectURI(URI(AUTH_CFG.oauth_redirect_base).segment("oauth").toString());

		// Configure the container terminal
		kubernetesContainerSocketProvider.WebSocketFactory = "ContainerWebSocket";
	})
	.config(function($compileProvider) {
		$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|git):/i);
	})
	.run(['mainNavTabs', "HawtioNav", function(tabs, HawtioNav) {
		for (var i = 0; i < tabs.length; i++) {
			HawtioNav.add(tabs[i]);
		}
	}])
	.run(function($rootScope, LabelFilter) {
		$rootScope.$on('$locationChangeSuccess', function(event) {
			LabelFilter.setLabelSelector(new LabelSelector({}, true), true);
		});
	})
	.run(function(dateRelativeFilter, durationFilter) {
		// Use setInterval instead of $interval because we're directly manipulating the DOM and don't want scope.$apply overhead
		setInterval(function() {
			$('.timestamp[data-timestamp]').text(function(i, existing) {
				return dateRelativeFilter($(this).attr("data-timestamp"), $(this).attr("data-drop-suffix")) || existing;
			});
		}, 30 * 1000);
		setInterval(function() {
			$('.duration[data-timestamp]').text(function(i, existing) {
				return durationFilter($(this).attr("data-timestamp")) || existing;
			});
		}, 1000);
	});

hawtioPluginLoader.addModule('openshiftConsole');
